<template>
  <div class="container clearfix">
    <div class="form">
      <div class="form-item">
        <div class="item-name">
          真实姓名
        </div>
        <input type="text"
               v-model="realname"
               placeholder-class="rgba(204,204,204,1)"
               class="item-inp"
               placeholder="请输入您的真实姓名">
      </div>
      <div class="form-item">
        <div class="item-name">
          身份证号
        </div>
        <input type="idcard"
               v-model="id_num"
               placeholder-class="rgba(204,204,204,1)"
               class="item-inp"
               maxlength="18"
               placeholder="请输入您的身份证号">
      </div>
    </div>
    <div class="sub-btn"
         @click="identification()">
      提交
    </div>
  </div>
</template>


<script>
import common from '@/assets/js/mmk_common.js'
export default {
  data () {
    return {
      realname: "",
      id_num: "",
      status: -1 //从确认预约跳过来的
    };
  },
  methods: {
    identification () {
      var that = this;
      if (this.realname == "") {
        wx.showToast({
          title: "真实姓名不能为空", //提示的内容,
          icon: "none", //图标,
          duration: 2000, //延迟时间,
          mask: true //显示透明蒙层，防止触摸穿透
        });
        return false;
      } else if (this.id_num == "") {
        wx.showToast({
          title: "身份证号不能为空", //提示的内容,
          icon: "none", //图标,
          duration: 2000, //延迟时间,
          mask: true //显示透明蒙层，防止触摸穿透
        });
        return false;
      } else {
        wx.showLoading({
          title: "提交中...", //提示的内容,
          mask: true, //显示透明蒙层，防止触摸穿透,
          success: res => { }
        });
        common.fly_post("api/v4_2/set_auth", {
          realname: this.realname,
          identity: this.id_num
        }, result => {
          wx.hideLoading();
          let res = result.data;
          if (res.status_code == 0) {
            wx.showToast({
              title: "一级实名认证成功", //提示的内容,
              icon: "none", //图标,
              duration: 2000, //延迟时间,
              mask: true, //显示透明蒙层，防止触摸穿透
              success () {
                wx.navigateBack({
                  delta: 1 //返回的页面数，如果 delta 大于现有页面数，则返回到首页,
                });
              }
            });
          } else {
            wx.showToast({
              title: res.message,
              icon: "none",
              duration: 2000,
              mask: false
            });
          }
        })
      }
    }
  },
  onLoad (options) {
    wx.setNavigationBarTitle({
      title: "用户认证"
    });
    Object.assign(this.$data, this.$options.data());
    if (options.status) {
      this.status = options.status;
    }
  }
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  background: rgba(243, 244, 246, 1);
  box-sizing: border-box;
  .form {
    width: 100%;
    background-color: #fff;
    .form-item {
      width: 100%;
      height: 44px;
      display: flex;
      border-bottom: 1px solid rgba(251, 251, 251, 1);
      .item-name {
        line-height: 44px;
        padding: 0 15px;
        font-size: 14px;
        font-family: " PingFangSC-Regular";
        color: rgba(51, 51, 51, 1);
      }
      .item-inp {
        flex: 1;
        height: 100%;
        border: none;
        outline: none;
        font-size: 17px;
        font-family: "Regular";
        color: #444;
      }
    }
  }
  .sub-btn {
    width: 100%;
    height: 50px;
    line-height: 50px;
    text-align: center;
    color: #fff;
    font-size: 20px;
    background: rgba(255, 56, 62, 1);
    position: absolute;
    bottom: 0px;
  }
}
</style>
